package com.xunyin.schedule;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class Runner implements ApplicationRunner {

    @Value("${tuya.url}")
    private String tuyaUrl;

    @Value("${tuya.client_id}")
    private String tuyaClientId;

    @Value("${tuya.client_secret}")
    private String tuyaClientSecret;

    @Override
    public void run(ApplicationArguments args) {
        // 调试中暂时注释
/*        try {
            if(StringUtils.isNotEmpty(TokenCache.getAccessTokenCache(tuyaClientId))) {
                return;
            }
            String getTokenPath = "/v1.0/token?grant_type=1";
            Object res = RequestSignUtils.execute(getTokenPath, "GET", "", new HashMap<>());
            Gson gson = new Gson();
            String str = gson.toJson(res);
            JSONObject resJson = JSONObject.parseObject(str);
            if(resJson.getBoolean("success")) {
                JSONObject resultJson = resJson.getJSONObject("result");
                TokenCache.setAccessTokenCache(tuyaClientId, resultJson.getString("access_token"));
                TokenCache.setRefreshTokenCache(tuyaClientId, resultJson.getString("refresh_token"));
                log.info("Runner -> get token success!");
            } else {
                log.error("Runner -> get token error! res={}", res);
            }
        } catch (Exception e) {
            log.error("Runner -> get token error! e：{}", e);
        }*/

    }
}
